package org.odata4j.examples.producer.jpa.contacts;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * A JPA annotated @Embeddable class that models an {@link AuditLog} event.
 */
@Embeddable
public class AuditLog implements Serializable {
  private static final long serialVersionUID = 1L;

  @Column(name = "Id")
  private Integer id;
  @Column(name = "Desc")
  private String desc;
  @Temporal(TemporalType.TIME)
  @Column(name = "CreatedTime", nullable = false, length = 8)
  private Date createdTime;
  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "LastModified", nullable = false)
  private Calendar lastModified;

  public AuditLog() {}

  public Integer getId() {
    return id;
  }

  public void setId(Integer id) {
    this.id = id;
  }

  public String getDesc() {
    return desc;
  }

  public void setDesc(String desc) {
    this.desc = desc;
  }

  public Date getCreatedTime() {
    return createdTime;
  }

  public void setCreatedTime(Date createdTime) {
    this.createdTime = createdTime;
  }

  public Calendar getLastModified() {
    return lastModified;
  }

  public void setLastModified(Calendar lastModified) {
    this.lastModified = lastModified;
  }

  @Override
  public int hashCode() {
    int hash = 0;
    hash += (id != null ? id.hashCode() : 0);
    hash += (desc != null ? desc.hashCode() : 0);
    hash += (createdTime != null ? createdTime.hashCode() : 0);
    hash += (lastModified != null ? lastModified.hashCode() : 0);
    return hash;
  }

  @Override
  public boolean equals(Object object) {
    if (!(object instanceof AuditLog)) {
      return false;
    }
    AuditLog other = (AuditLog) object;
    
    if ((id == null && other.id != null)
        || (id != null && !id.equals(other.id))) {
      return false;
    }
    if ((desc == null && other.desc != null)
        || (desc != null && !desc.equals(other.desc))) {
      return false;
    }
    if ((createdTime == null && other.createdTime != null)
        || (createdTime != null && !createdTime.equals(other.createdTime))) {
      return false;
    }
    if ((lastModified == null && other.lastModified != null)
        || (lastModified != null && !lastModified.equals(other.lastModified))) {
      return false;
    }
    
    return true;
  }

  @Override
  public String toString() {
    return "org.odata4j.examples.producer.jpa.northwind.AuditLog[id=" + id 
        + ", desc=" + desc + ", CreatedTime=" + createdTime + ", LastModified=" + lastModified + "]";
  }

}
